<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./node_modules/vue/dist/vue.js"></script>
</head>

<body>
  <div id="app">
    <table border="1">
      <thead>
        <tr>
          <th>id</th>
          <th>姓名</th>
          <th>邮箱</th>
          <th>性别</th>
          <th>爱好</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>

        <tr v-for="user in formData">
          <td>{{user.id}}</td>
          <td>{{user.username}}</td>
          <td>{{user.email}}</td>
          <td>{{user.gender}}</td>
          <td>{{user.hobby | hobbyFilter }}</td>
          <td><button @click="handleDel(user.id)">删除</button></td>
        </tr>
      </tbody>
    </table>
  </div>

  <script>
    const formData = [
      {
        id: 1,
        username: "小红",
        email: "xiaohong@qq.com",
        gender: "女",
        hobby: ["游泳", "读书"],
      },
      {
        id: 2,
        username: "小黑",
        email: "xiaohei@qq.com",
        gender: "男",
        hobby: ["篮球", "读书", "编程"],
      },
      {
        id: 3,
        username: "小亮",
        email: "xiaoliang@qq.com",
        gender: "男",
        hobby: ["篮球", "读书", "编程"],
      },
      {
        id: 4,
        username: "小五",
        email: "xiaowu@qq.com",
        gender: "男",
        hobby: ["篮球", "读书", "编程"],
      },
      {
        id: 5,
        username: "小海",
        email: "aaa@qq.com",
        gender: "男",
        hobby: ["篮球", "读书", "编程"],
      },
      {
        id: 6,
        username: "小紫",
        email: "aaa@qq.com",
        gender: "男",
        hobby: ["篮球", "读书", "编程"],
      },
    ];
    const vm = new Vue({
      el: "#app",
      data: {
        formData
      },
      methods: {
        handleDel(id) {
          const index = this.formData.findIndex(item => {
            return item.id === id
          });
          this.formData.splice(index, 1)
        }
      },
      filters: {
        hobbyFilter(hobby) {
          return hobby.join(" | ")
        }
      }
    })
  </script>
</body>

</html>
